<body class="wy-body">

<script>
$(function(){
	$("#bak_sql").click(function(){
		// window.onbeforeunload = function(){ return "正在备份数据库，请不要关闭！" }
		bak_sql_fun(0,0);
	});

});
function bak_sql_fun(tab_i,num_i){
	if(num_i == 0){
		show_progress(tab_i, "开始备份...(0%)");
	}
	$.post("{:url('Database/export')}",{id:tab_i,start:num_i},function(data){
		if(data.code == 1){
			if(data.data.start == 0){
				show_progress(tab_i, "开始备份...(100%)");
			}else{
				show_progress(tab_i, "开始备份...("+(data.data.start*100/data.data.count)+"%)");
			}
			
			bak_sql_fun(data.data.id, data.data.start);
		}else{
			alert(data.msg);
		}
	},"JSON");
}
function show_progress(index,msg){
	$("table[name='wy_table_lists']").find("tbody>tr").eq(index).find("td.progress").html(msg);
}
var _nuit = ['b','Kb','Mb','Gb','Tb']
function show_data(num){
	var k = 0; 
	var num = num || 0;
	num = parseFloat(num);
	while(num >= 1024 && k < (_nuit.length-1)){
		num = num/1024;
		k++;
	}
	return (parseFloat(num.toFixed(2)) + 0)  + ' ' + _nuit[k];
}

function show_num(num){
	var str = num.toString();
	var reg = str.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
	return str.replace(reg,"$1,");
}

</script>
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-body">
<table class="layui-table" name="wy_table_lists" lay-filter="wy_table_lists">
<thead>
<thead>
<tr>
	<th lay-data="{field:'name'}">备份名称</th>
	<th lay-data="{field:'part'}">备份卷数</th>
	<th lay-data="{field:'compress',templet:'#compress'}">备份压缩</th>
	<th lay-data="{field:'#size',templet:'#size'}">备份大小</th>
	<th lay-data="{field:'time'}">备份时间</th>
	<th lay-data="{toolbar:'#barTool'}">操作</th>
</tr>
</thead>
<tbody>
{volist name="datalist" id="vo"}
<tr>
	<td>{$vo.id}</td>
	<td>{$vo.part}</td>
	<td>{$vo.compress}</td>
	<td><script>document.write(show_data('{$vo.size}'));</script></td>
	<td>{$vo.time}</td>
	<td>
		<div class="layui-btn-group">
			
			<!-- <a class="layui-btn layui-btn-xs layui-btn-primary wy_but"  -->
				<!-- wy-event="lay_ajax_get" -->
				<!-- wy-url="{:url('import')}?id={$vo.id}" -->
				<!-- wy-tips="" -->
				<!-- wy-table="wy_table_lists" -->
			<!-- >恢复</a> -->
		
			<a class="layui-btn layui-btn-xs layui-btn-primary wy_but" 
				wy-event="lay_ajax_get"
				wy-url="{:url('del')}?id={$vo.id}"
				wy-tips="确认是否删除该信息，删除以后将无法恢复"
				wy-refresh="1"
			>删除</a>
		
		</div>
	</td>
</tr>
{/volist}
</tbody>
</table>
		</div>
	</div>
</div>
</body>